<#assign basePath = request.contextPath >
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Basic DataGrid - jQuery EasyUI Demo</title>
   	<link rel="stylesheet" type="text/css" href="${basePath}/resources/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${basePath}/resources/easyui/themes/icon.css">
	<script type="text/javascript" src="${basePath}/resources/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="${basePath}/resources/easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<div id="tb" style="padding:3px">
	    <span>查询关键字:</span>
	    <input id="keyword" style="line-height:26px;border:1px solid #ccc">
	    <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-ok" onclick="doSearch()">Search</a>
	</div>
    <table class="easyui-datagrid" height="600px" title="查询结果" toolbar="#tb"
    	data-options="singleSelect:true,collapsible:true,pagination:true,pageSize:10,method:'get'">
        <thead>
            <tr>
                <th data-options="field:'nickname',align:'center'">微博昵称</th>
                <th data-options="field:'avatar',align:'center', width:100" formatter='formatPic'>微博头像</th>
                <th data-options="field:'addUrl',align:'center'" formatter='formatAddUrl'>关注链接</th>
                <th data-options="field:'mainpage',align:'center'" formatter='formatMainPage'>添加定时任务</th>
            </tr>
        </thead>
    </table>
 
 	<script type="text/javascript">
 		$(function(){
 			var pager = $('.easyui-datagrid').datagrid('getPager');
 		});
 		
 		function formatPic(val,row){
	        return "<img src='"+ val + "'/>";
		}
		
		function formatAddUrl(val,row){
	        return "<a href='javascript:void(0);' onclick='follow(\"" + val +"\")'>关注他</a>";
		}
		
		function formatMainPage(val, row){
			return "<a href='javascript:void(0);' onclick='addJob(\"" + val +"\")'>添加定时任务</a>";
		}
		
		function follow(addurl){
			if(addurl){
				$.ajax({
					url: '${basePath}/sina/user/follow.json',
					data:{
						addUrl : addurl
					},
					success: function(data){
					}
				});
			}
		}
		
		function addJob(mainpage){
			if(!mainpage){
				return;
			}
			$.ajax({
				url : '${basePath}/sina/addJob.json',
				data:{
					mainpage : mainpage
				},
				success: function(data){
				}
			})
		}
		
 		function doSearch(){
 			var keyword = $("#keyword").val();
 			if(keyword){
	 			$('.easyui-datagrid').datagrid({
	 				url: '${basePath}/sina/search/user.json?keyword='+$("#keyword").val()
	 			});
 			}else{
 				alert("请先填写查询关键字");
 			}
		}
 	</script>
</body>
</html>